/**
 * 70. 爬楼梯
 */
public class Solution_70 {
    /**
     * 动态规划，优化内存占用
     */
    public int climbStairs(int n) {
        int p = 0, q = 0, r = 1;
        for (int i = 1; i <= n; i++) {
            p = q;
            q = r;
            r = p + q;
        }
        return r;
    }

    /**
     * 动态规划
     */
    public int climbStairs1(int n) {
        // dp[i] 表示爬到 i 阶台阶有几种方法
        int[] dp = new int[n + 1];
        dp[1] = 1;
        dp[2] = 2;
        for (int i = 3; i < dp.length; i++) {
            dp[i] = dp[i - 1] + dp[i - 2];
        }
        return dp[n];
    }

    public static void main(String[] args) {
        Solution_70 solution = new Solution_70();
        int ans = solution.climbStairs(3);
        System.out.println(ans);
    }
}